import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { UserInfo } from "#/entity";

interface SingleUserSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedUser?: UserInfo) => void;
}

const SingleUserSelector:React.FC<SingleUserSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的用户
  const [selectedUser, setSelectedUser] = useState<UserInfo>();

  const handleOk = () => {
		onOk(selectedUser);
	};

	return (
		<Modal title="选择用户" open={open} onCancel={onCancel} onOk={handleOk} width={700} destroyOnClose>
			<DynamicQueryTable 
        reportCode="single_user_select_report"
        selectionType={SelectionType.RADIO}
        onSelectChange={(selectedRows) => {setSelectedUser(selectedRows[0])}}  
      />
		</Modal>
	);
}

export default SingleUserSelector;